package com.qf.purchasing.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.purchasing.qo.DetailQO;
import com.qf.purchasing.service.DetailService;
import com.qf.purchasing.vo.DetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/detail")
//类上，tags=模块名
@Api(tags = "采购明细 ")
public class DetailController {
    @Resource
    private DetailService detailService;

    @GetMapping("/list")
    @ApiOperation("分页查询指定采购计划的采购明细")
    @ApiImplicitParams({
            //                参数名，       参数说明，         是否必填， 参数请求类型：query,header,path  参数数据类型，   参数默认值           示例
            @ApiImplicitParam(name = "page", value = "当前页数", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "1", example = "page=1"),
            @ApiImplicitParam(name = "size", value = "展示量", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "10"),
            @ApiImplicitParam(name = "sid", value = "计划表id", required = true)
    })
    public PageInfo<DetailVO> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, @RequestParam(required = true) int sid) {
        return detailService.query(page, size, sid);
    }

    @PostMapping("/insert")
    @ApiOperation("添加采购明细")
    public RespResult<String> addDetail(DetailQO detailQO) {
        return detailService.addDetailService(detailQO);
    }

    @PutMapping("/delete")
    @ApiOperation("删除采购明细记录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "detailIds", value = "采购明细id数组", required = true)
    )
    public RespResult<String> deleteDetails(int[] detailIds) {
        return detailService.deleteDetailByIds(detailIds);
    }

    @PutMapping("/update")
    @ApiOperation("修改采购明细记录")
    public RespResult<String> modifyDetail(DetailQO detailQO) {
        return detailService.modify(detailQO);
    }

    @GetMapping("/select")
    @ApiOperation("根据id查询明细记录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "detailId", value = "采购明细id", required = true)
    )
    public RespResult<DetailVO> queryDetailById(int detailId) {
        return detailService.selectDetailById(detailId);
    }


}
